package com.solvePlat.config;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.stream.ChunkedWriteHandler;

public class WebChatServerInitize extends ChannelInitializer {

    protected void initChannel(Channel channel) throws Exception {//判断是否是websocket请求

        ChannelPipeline channelPipline =  channel.pipeline();//这个管道需要流经多少道工序

        channelPipline.addLast(new HttpServerCodec())//将请求和应答消息编码为http协议的消息
                      .addLast(new HttpObjectAggregator(64*1024))
                      .addLast(new WebSocketServerProtocolHandler("/chat"))//只要请求的是chat则就是websocket请求
                      .addLast(new TextWebSocketFrameHandler());
    }
}
